home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / RCS_56.ARJ / CONF.SH < prev    next >
Linux/UNIX/POSIX Shell Script  |  1992-02-11  |  36KB  |  1,672 lines

  1. #!/bin/sh
  2. # Output RCS compile-time configuration.
  3. Id='$Id: conf.sh,v 5.14 1991/11/20 18:21:10 eggert Exp $'
  4. #    Copyright 1990, 1991 by Paul Eggert
  5. #    Distributed under license by the Free Software Foundation, Inc.
  6.  
  7. # This file is part of RCS.
  8. #
  9. # RCS is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. #
  14. # RCS is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with RCS; see the file COPYING.  If not, write to
  21. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22. #
  23. # Report problems and direct all questions to:
  24. #
  25. #     rcs-bugs@cs.purdue.edu
  26.  
  27.  
  28. # Standard output should already be directed to "a.h";
  29. # later parts of this procedure need it.
  30. # Standard error can be ignored if a.h is OK,
  31. # and can be inspected for clues otherwise.
  32.  
  33. # The Makefile overrides the following defaults.
  34. : ${CC=cc}
  35. : ${CFLAGS=-O}
  36. : ${COMPAT2=0}
  37. : ${DIFF3=${RCSPREFIX}diff3}
  38. : ${DIFF3_BIN=1}
  39. : ${DIFF=${RCSPREFIX}diff}
  40. : ${DIFF_FLAGS=-an}
  41. : ${DIFF_L=1}
  42. : ${DIFF_SUCCESS=0} ${DIFF_FAILURE=1} ${DIFF_TROUBLE=2}
  43. : ${ED=/bin/ed}
  44. : ${RCSPREFIX=/usr/local/bin/}
  45. : ${SENDMAIL='"/usr/lib/sendmail"'}
  46. # : ${LDFLAGS=} ${LDLIBS=} tickles old shell bug
  47.  
  48. C="$CC $CFLAGS"
  49. CL="$CC $CFLAGS $LDFLAGS"
  50. L=$LDLIBS
  51. RM='rm -f a.out'
  52.  
  53. cat <<EOF
  54. /* RCS compile-time configuration */
  55.  
  56.     /* $Id */
  57.  
  58. /*
  59.  * This file is generated automatically.
  60.  * If you edit it by hand your changes may be lost.
  61.  * Instead, please try to fix conf.sh,
  62.  * and send your fixes to rcs-bugs@cs.purdue.edu.
  63.  */
  64.  
  65. EOF
  66.  
  67. : exitmain
  68. cat >a.c <<EOF
  69. #include "a.h"
  70. int main(argc,argv) int argc; char **argv; { return argc-1; }
  71. EOF
  72. $RM && $CL a.c $L >&2 || exit
  73. e='exit(n), 3 /* lint fodder */'
  74. if ./a.out -
  75. then :
  76. elif ./a.out
  77. then e=n
  78. fi
  79. echo "#define exitmain(n) return $e /* how to exit from main() */"
  80.  
  81. : _POSIX_SOURCE
  82. cat >a.c <<'EOF'
  83. #include "a.h"
  84. #include <stdio.h>
  85. int main() { exitmain(fileno(stdout) < 0); }
  86. EOF
  87. a='/* ' z='*/ '
  88. $RM || exit
  89. if ($CL a.c $L && ./a.out) >&2
  90. then :
  91. elif $RM || exit; ($CL -D_POSIX_SOURCE a.c $L && ./a.out) >&2
  92. then a= z=
  93. fi
  94. cat <<EOF
  95. $a#define _POSIX_SOURCE $z/* Define this if Posix + strict Standard C.  */
  96.  
  97. #include <errno.h>
  98. #include <stdio.h>
  99. #include <time.h>
  100. EOF
  101.  
  102. cat <<'EOF'
  103.  
  104. /* Comment out #include lines below that do not work.  */
  105. EOF
  106.  
  107. # Run `$CS a.c $LS' instead of `$CL a.c $L' for compile-time checking only.
  108. # This speeds up the configuration process.
  109. if $C -S a.c >&2
  110. then CS="$C -S" LS=    # Generate assembly language output.
  111. elif $C -c a.c >&2
  112. then CS="$C -c" LS=    # Generate object code.
  113. else CS=$CL LS=$L    # Generate an executable.
  114. fi
  115.  
  116. # standard include files
  117. # sys/types.h and sys/stat.h must come first because others depend on them.
  118. has_signal=1
  119. for h in \
  120.     sys/types sys/stat \
  121.     dirent fcntl limits pwd signal stdlib string sys/mman sys/wait unistd utime vfork
  122. do
  123.     i="#include <$h.h>"
  124.     : $i
  125.     cat >a.c <<EOF
  126. #include "a.h"
  127. $i
  128. int main(){ exitmain(0); }
  129. EOF
  130.     $RM || exit
  131.     ($CL a.c $L && ./a.out) >&2 || {
  132.         case $h in
  133.         string)
  134.             i='#include <strings.h>';;
  135.         *)
  136.             i="/* $i */"
  137.         esac
  138.         case $h in
  139.         signal) has_signal=0
  140.         esac
  141.     }
  142.     echo "$i"
  143. done
  144.  
  145. cat <<'EOF'
  146.  
  147. /* Define the following symbols to be 1 or 0.  */
  148. EOF
  149.  
  150. # has_sys_*_h
  151. for H in dir param
  152. do
  153.     : has_sys_${H}_h
  154.     cat >a.c <<EOF
  155. #include "a.h"
  156. #include <sys/$H.h>
  157. int main() { exitmain(0); }
  158. EOF
  159.     $RM || exit
  160.     if ($CL a.c $L && ./a.out) >&2
  161.     then h=1
  162.     else h=0
  163.     fi
  164.     echo "#define has_sys_${H}_h $h /* Does #include <sys/$H.h> work?  */"
  165. done
  166.  
  167.  
  168. # We must do NAME_MAX and has_readlink next, because they might generate
  169. # #include directives that affect later definitions.
  170.  
  171. : NAME_MAX
  172. cat >a.c <<'EOF'
  173. #include "a.h"
  174. char b[NAME_MAX + 2];
  175. main()
  176. {
  177. #if !defined(NAME_MAX)
  178.     exitmain(1);
  179. #else
  180.     int i;
  181.     b[0] = 'a'; b[1] = '.';
  182.     for (i = 2;  i < NAME_MAX;  i++)
  183.         b[i] = 'a';
  184.     b[i] = 'b';
  185.     exitmain(creat(b, 0) < 0);
  186. #endif
  187. }
  188. EOF
  189. $RM a.*ab || exit
  190. if $CL a.c $L >&2 && ./a.out && test -f a.*ab
  191. then a= z=
  192. else a='/* ' z='*/ '
  193. fi
  194. rm -f a.*ab || exit
  195.  
  196. : has_readlink
  197. cat >a.c <<'EOF'
  198. #include "a.h"
  199. char b[7];
  200. int main()
  201. {
  202.     exitmain(readlink("a.sym2",b,7) != 6  ||  strcmp(b, "a.sym1") != 0);
  203. }
  204. EOF
  205. $RM a.sym* || exit
  206. if (ln -s a.sym1 a.sym2 && $CL a.c $L && ./a.out) >&2
  207. then h=1
  208. else h=0
  209. fi
  210. cat <<EOF
  211. #define has_readlink $h /* Does readlink() work?  */
  212.  
  213. $a#undef NAME_MAX $z/* Uncomment this if NAME_MAX is broken.  */
  214.  
  215. #if !defined(NAME_MAX) && !defined(_POSIX_NAME_MAX)
  216. #    if has_sys_dir_h
  217. #        include <sys/dir.h>
  218. #    endif
  219. #    ifndef NAME_MAX
  220. #        ifndef MAXNAMLEN
  221. #            define MAXNAMLEN 14
  222. #        endif
  223. #        define NAME_MAX MAXNAMLEN
  224. #    endif
  225. #endif
  226. #if !defined(PATH_MAX) && !defined(_POSIX_PATH_MAX)
  227. #    if has_sys_param_h
  228. #        include <sys/param.h>
  229. #        define included_sys_param_h 1
  230. #    endif
  231. #    ifndef PATH_MAX
  232. #        ifndef MAXPATHLEN
  233. #            define MAXPATHLEN 1024
  234. #        endif
  235. #        define PATH_MAX (MAXPATHLEN-1)
  236. #    endif
  237. #endif
  238. #if has_readlink && !defined(MAXSYMLINKS)
  239. #    if has_sys_param_h && !included_sys_param_h
  240. #        include <sys/param.h>
  241. #    endif
  242. #    ifndef MAXSYMLINKS
  243. #        define MAXSYMLINKS 20 /* BSD; not standard yet */
  244. #    endif
  245. #endif
  246. EOF
  247.  
  248. cat <<'EOF'
  249.  
  250. /* Comment out the keyword definitions below if the keywords work.  */
  251. EOF
  252.  
  253. : const, volatile
  254. for i in const volatile
  255. do
  256.     cat >a.c <<EOF
  257. #    include "a.h"
  258.     enum Boolean { false, true };
  259.     static enum Boolean $i zero;
  260.     static enum Boolean $i * $i azero = &zero;
  261.     static enum Boolean $i * $i * $i aazero = &azero;
  262.     int main() { exitmain(!!**aazero); }
  263. EOF
  264.     a= z=
  265.     if $CS a.c $LS >&2
  266.     then
  267.         cat >a.c <<EOF
  268.             typedef unsigned char $i *Iptr_type;
  269.             struct { Iptr_type lim; } s, *f = &s;
  270.             int main() {
  271.                 Iptr_type lim;
  272.                 lim = f->lim;
  273.                 return !!lim;
  274.             }
  275. EOF
  276.         if $CS a.c $LS >&2
  277.         then a='/* ' z=' */'
  278.         fi
  279.     fi
  280.     echo "$a#define $i$z"
  281. done
  282.  
  283. # *_t
  284. cat <<'EOF'
  285.  
  286. /* Comment out the typedefs below if the types are already declared.  */
  287. /* Fix any uncommented typedefs that are wrong.  */
  288. EOF
  289. cat >a.c <<'EOF'
  290. #include "a.h"
  291. t x;
  292. int main() { exitmain(0); }
  293. EOF
  294. for t in mode_t pid_t sig_atomic_t size_t ssize_t time_t uid_t
  295. do
  296.     : $t
  297.     case $t in
  298.     size_t) i=unsigned;;
  299.     time_t) i=long;;
  300.     *) i=int;;
  301.     esac
  302.     if $CS -Dt=$t a.c $LS >&2
  303.     then a='/* ' z=' */'
  304.     else a= z=
  305.     fi
  306.     echo "${a}typedef $i $t;$z"
  307. done
  308.  
  309. : has_prototypes, has_stdarg, has_varargs, va_start_args
  310. cat >a.ha <<'EOF'
  311. #if has_prototypes
  312. #    define P(params) params
  313. #else
  314. #    define P(params) ()
  315. #endif
  316. #if has_stdarg
  317. #    include <stdarg.h>
  318. #else
  319. #    if has_varargs
  320. #        include <varargs.h>
  321. #    else
  322.         typedef char *va_list;
  323. #        define va_dcl int va_alist;
  324. #        define va_start(ap) ((ap) = (va_list)&va_alist)
  325. #        define va_arg(ap,t) (((t*) ((ap)+=sizeof(t)))  [-1])
  326. #        define va_end(ap)
  327. #    endif
  328. #endif
  329. #if va_start_args == 2
  330. #    define vararg_start va_start
  331. #else
  332. #    define vararg_start(ap,p) va_start(ap)
  333. #endif
  334. EOF
  335. cat >a.c <<'EOF'
  336. #include "a.h"
  337. #include "a.ha"
  338. #if has_prototypes
  339. char *f(char **p, ...)
  340. #else
  341. char *f(p, va_alist) char **p; va_dcl
  342. #endif
  343. {
  344.     char *s;
  345.     va_list v;
  346.     vararg_start(v,p);
  347.     s = p[va_arg(v,int)];
  348.     va_end(v);
  349.     return s;
  350. }
  351. int main P((int, char**));
  352. int main(argc, argv) int argc; char **argv; {
  353.     exitmain(f(argv,0) != argv[0]  ||  f(argv,1) != argv[1]);
  354. }
  355. EOF
  356. for has_prototypes in 1 0
  357. do
  358.     for has_stdarg in 1 v 0
  359.     do
  360.         case $has_stdarg in
  361.         v) has_varargs=1 has_stdarg=0;;
  362.         *) has_varargs=0
  363.         esac
  364.         case $has_stdarg in
  365.         0) as='1 2';;
  366.         1) as='2 1'
  367.         esac
  368.         for va_start_args in $as
  369.         do
  370.             $RM || exit
  371.             $CL \
  372.                 -Dhas_prototypes=$has_prototypes \
  373.                 -Dhas_stdarg=$has_stdarg \
  374.                 -Dhas_varargs=$has_varargs \
  375.                 -Dva_start_args=$va_start_args \
  376.                 a.c $L >&2 && ./a.out && break
  377.         done && break
  378.     done && break
  379. done || {
  380.     echo >&2 "cannot deduce has_prototypes, has_stdarg, va_start_args"
  381.     exit 1
  382. }
  383. cat - a.ha <<EOF
  384.  
  385. /* Define the following symbols to be 1 or 0.  */
  386. #define has_prototypes $has_prototypes /* Do function prototypes work?  */
  387. #define has_stdarg $has_stdarg /* Does <stdarg.h> work?  */
  388. #define has_varargs $has_varargs /* Does <varargs.h> work?  */
  389. #define va_start_args $va_start_args /* How many args does va_start() take?  */
  390. EOF
  391.  
  392. : text_equals_binary_stdio, FOPEN_...
  393. cat >a.c <<'EOF'
  394. #include "a.h"
  395.     int
  396. copyto(filename, mode)
  397.     char const *filename, *mode;
  398. {
  399.     int c;
  400.     FILE *f, *g;
  401.     if (!(f = fopen("a.out", "rb")) || !(g = fopen(filename, mode)))
  402.         return 1;
  403.     while (c=getc(f), !feof(f))
  404.         if (ferror(f)  ||  putc(c,g)<0 && ferror(g))
  405.             return 1;
  406.     return fclose(f)!=0 || fclose(g)!=0;
  407. }
  408. int main() { exitmain(copyto("a.d", "w+b") || copyto("a.e", "w+")); }
  409. EOF
  410. e=1
  411. $RM a.d a.e || exit
  412. $CL a.c $L >&2 && ./a.out && cmp a.out a.d && {
  413.     cmp a.out a.e || e=0
  414. }
  415. cat <<EOF
  416.  
  417. #define text_equals_binary_stdio $e /* Does stdio treat text like binary?  */
  418. #define text_work_stdio 0 /* Text i/o for working file, binary for RCS file?  */
  419. #if text_equals_binary_stdio
  420.     /* Text and binary i/o behave the same, or binary i/o does not work.  */
  421. #    define FOPEN_R "r"
  422. #    define FOPEN_W "w"
  423. #    define FOPEN_WPLUS "w+"
  424. #else
  425.     /* Text and binary i/o behave differently.  */
  426.     /* This is incompatible with Posix and Unix.  */
  427. #    define FOPEN_R "rb"
  428. #    define FOPEN_W "wb"
  429. #    define FOPEN_WPLUS "w+b"
  430. #endif
  431. #if text_work_stdio
  432. #    define FOPEN_R_WORK "r"
  433. #    define FOPEN_W_WORK "w"
  434. #    define FOPEN_WPLUS_WORK "w+"
  435. #else
  436. #    define FOPEN_R_WORK FOPEN_R
  437. #    define FOPEN_W_WORK FOPEN_W
  438. #    define FOPEN_WPLUS_WORK FOPEN_WPLUS
  439. #endif
  440.  
  441. /* Define or comment out the following symbols as needed.  */
  442. EOF
  443.  
  444. : bad_fopen_wplus
  445. cat >a.c <<'EOF'
  446. #include "a.h"
  447. int main() { exitmain(!fopen("a.d",FOPEN_WPLUS)); }
  448. EOF
  449. $RM || exit
  450. if echo nonempty >a.d && $CL a.c $L >&2 && ./a.out && test ! -s a.d
  451. then b=0
  452. else b=1
  453. fi
  454. echo "#define bad_fopen_wplus $b /* Does fopen(f,FOPEN_WPLUS) fail to truncate f?  */"
  455.  
  456. : getlogin_is_secure
  457. echo "#define getlogin_is_secure 0 /* Is getlogin() secure?  Usually it's not.  */"
  458.  
  459. : has_dirent
  460. cat >a.c <<'EOF'
  461. #include "a.h"
  462. int main() {
  463.     DIR *d = opendir(".");
  464.     struct dirent *e;
  465.     while ((e = readdir(d)))
  466.         if (strcmp(e->d_name, "a.c") == 0  &&  closedir(d) == 0)
  467.             exitmain(0);
  468.     exitmain(1);
  469. }
  470. EOF
  471. $RM || exit
  472. if $CL a.c $L >&2 && ./a.out
  473. then h=1
  474. else h=0
  475. fi
  476. echo "#define has_dirent $h /* Do opendir(), readdir(), closedir() work?  */"
  477.  
  478. : has_fchmod
  479. cat >a.c <<'EOF'
  480. #include "a.h"
  481. int main() { exitmain(fchmod(fileno(stdin),0) != 0); }
  482. EOF
  483. $RM || exit
  484. if $CL a.c $L >&2 && ./a.out <a.c && test ! -r a.c
  485. then h=1
  486. else h=0
  487. fi
  488. echo "#define has_fchmod $h /* Does fchmod() work?  */"
  489. rm -f a.c || exit
  490.  
  491. : has_fputs
  492. cat >a.c <<'EOF'
  493. #include "a.h"
  494. int main() { exitmain(fputs("Hello\"\nworld", stdout) != 12); }
  495. EOF
  496. Hello='Hello"
  497. world'
  498. $RM || exit
  499. if $CL a.c $L >&2 && ./a.out >/dev/null && x=`./a.out` && test " $x" = " $Hello"
  500. then h=1
  501. else h=0
  502. fi
  503. echo "#define has_fputs $h /* Does fputs() work?  */"
  504.  
  505. : has_ftruncate
  506. cat >a.c <<'EOF'
  507. #include "a.h"
  508. int main(argc, argv) int argc; char **argv; {
  509.     int f = creat(argv[1], 0);
  510.     if (f<0 || write(f,"abc",3)!=3 || ftruncate(f,(off_t)0)!=0 || close(f)!=0)
  511.             exitmain(1);
  512.     exitmain(0);
  513. }
  514. EOF
  515. $RM || exit
  516. if $CL a.c $L >&2
  517. then
  518.     h=1
  519.     # Check out /tmp too; it's buggy on some hosts.
  520.     for d in . /tmp
  521.     do
  522.         if test -d $d
  523.         then
  524.             f=$d/a.d
  525.             rm -f $f || exit
  526.             ./a.out $f && test ! -s $f && test -f $f  ||  h=0
  527.             rm -f $f || exit
  528.         fi
  529.     done
  530. else h=0
  531. fi
  532. echo "#define has_ftruncate $h /* Does ftruncate() work?  */"
  533.  
  534. : has_getuid
  535. cat >a.c <<'EOF'
  536. #include "a.h"
  537. #ifndef getuid
  538.     uid_t getuid();
  539. #endif
  540. int main() { exitmain(getuid()!=getuid()); }
  541. EOF
  542. $RM || exit
  543. if ($CL a.c $L && ./a.out) >&2
  544. then has_getuid=1
  545. else has_getuid=0
  546. fi
  547. echo "#define has_getuid $has_getuid /* Does getuid() work?  */"
  548.  
  549. : has_getpwuid
  550. case $has_getuid in
  551. 0)
  552.     a='/* ' z='*/ ' h=?;;
  553. *)
  554.     a= z=
  555.     cat >a.c <<'EOF'
  556. #include "a.h"
  557. int main() { exitmain(!getpwuid(0)); }
  558. EOF
  559.     $RM || exit
  560.     if ($CL a.c $L && ./a.out) >&2
  561.     then h=1
  562.     else h=0
  563.     fi
  564. esac
  565. echo "$a#define has_getpwuid $h $z/* Does getpwuid() work?  */"
  566.  
  567. : has_link
  568. cat >a.c <<'EOF'
  569. #include "a.h"
  570. int main() { exitmain(link("a.c","a.d") != 0); }
  571. EOF
  572. $RM a.d || exit
  573. if ($CL a.c $L && ./a.out && cmp a.c a.d) >&2
  574. then h=1
  575. else h=0
  576. fi
  577. rm -f a.d || exit
  578. echo "#define has_link $h /* Does link() work?  */"
  579.  
  580. : has_memcmp
  581. cat >a.c <<'EOF'
  582. #include "a.h"
  583. int main() { exitmain(memcmp("beautiful","beautiful",10) != 0); }
  584. EOF
  585. $RM || exit
  586. if ($CL a.c $L && ./a.out) >&2
  587. then h=1
  588. else h=0
  589. fi
  590. echo "#define has_memcmp $h /* Does memcmp() work?  */"
  591.  
  592. : has_memcpy
  593. cat >a.c <<'EOF'
  594. #include "a.h"
  595. char a[3];
  596. int main() {
  597.     memcpy(a,"xy",3);
  598.     exitmain(strcmp(a,"xy")!=0);
  599. }
  600. EOF
  601. $RM || exit
  602. if ($CL a.c $L && ./a.out) >&2
  603. then h=1
  604. else h=0
  605. fi
  606. echo "#define has_memcpy $h /* Does memcpy() work?  */"
  607.  
  608. : has_memmove
  609. cat >a.c <<'EOF'
  610. #include "a.h"
  611. char a[4];
  612. int main() {
  613.     strcpy(a, "xy");
  614.     memmove(a+1, a, 3);
  615.     exitmain(strcmp(a,"xxy")!=0);
  616. }
  617. EOF
  618. $RM || exit
  619. if ($CL a.c $L && ./a.out) >&2
  620. then h=1
  621. else h=0
  622. fi
  623. echo "#define has_memmove $h /* Does memmove() work?  */"
  624.  
  625. : has_mmap, has_madvise
  626. cat >a.c <<'EOF'
  627. #define CHAR1 '#' /* the first character in this file */
  628. #include "a.h"
  629. #ifndef mmap
  630.     caddr_t mmap();
  631. #endif
  632. caddr_t a;
  633. struct stat b;
  634. #ifndef MADVISE_OK
  635. #    define MADVISE_OK (madvise(a,b.st_size,MADV_SEQUENTIAL)==0 && madvise(a,b.st_size,MADV_NORMAL)==0)
  636. #endif
  637. int main()
  638. {
  639.     if (fstat(fileno(stdin), &b) != 0)
  640.         exitmain(1);
  641.     a = mmap(
  642.         (caddr_t)0, b.st_size, PROT_READ, MAP_SHARED,
  643.         fileno(stdin), (off_t)0
  644.     );
  645.     exitmain(
  646.         a == (caddr_t)-1  ||
  647.         !MADVISE_OK ||
  648.         *a != CHAR1  ||
  649.         munmap(a, b.st_size)  !=  0
  650.     );
  651. }
  652. EOF
  653. a=0 has_mmap=0
  654. $RM || exit
  655. if ($CL -DMADVISE_OK=1 a.c $L && ./a.out <a.c) >&2
  656. then
  657.     has_mmap=1
  658.     $RM || exit
  659.     ($CL a.c $L && ./a.out <a.c) >&2 && a=1
  660. fi
  661. echo "#define has_madvise $a /* Does madvise() work?  */"
  662. echo "#define has_mmap $has_mmap /* Does mmap() work on regular files?  */"
  663.  
  664. : has_rename, bad_a_rename, bad_b_rename
  665. cat >a.c <<'EOF'
  666. #include "a.h"
  667. int main() { exitmain(rename("a.a","a.b") != 0); }
  668. EOF
  669. echo a >a.a && $RM a.b || exit
  670. if ($CL a.c $L && ./a.out && test -f a.b) >&2
  671. then
  672.     h=1
  673.     rm -f a.a a.b &&
  674.     echo a >a.a && chmod -w a.a || exit
  675.     if ./a.out && test ! -f a.a && test -f a.b
  676.     then a=0
  677.     else a=1
  678.     fi
  679.     rm -f a.a a.b &&
  680.     echo a >a.a && echo b >a.b && chmod -w a.b || exit
  681.     if ./a.out && test ! -f a.a && test -f a.b
  682.     then b=0
  683.     else b=1
  684.     fi
  685.     rm -f a.a a.b || exit
  686. else h=0 a=0 b=0
  687. fi
  688. echo "#define has_rename $h /* Does rename() work?  */"
  689. echo "#define bad_a_rename $a /* Does rename(A,B) fail if A is unwritable?  */"
  690. echo "#define bad_b_rename $b /* Does rename(A,B) fail if B is unwritable?  */"
  691.  
  692. : void, VOID
  693. cat >a.c <<'EOF'
  694. #include "a.h"
  695. void f() {}
  696. int main() {f(); exitmain(0);}
  697. EOF
  698. if $CS a.c $LS >&2
  699. then
  700.     v='(void) '
  701. else
  702.     v=
  703.     echo 'typedef int void;'
  704. fi
  705. echo "#define VOID $v/* 'VOID e;' discards the value of an expression 'e'.  */"
  706.  
  707. : has_seteuid
  708. case $has_getuid in
  709. 0)
  710.     a='/* ' z='*/ ' has_seteuid=?;;
  711. *)
  712.     a= z=
  713.     cat >a.c <<'EOF'
  714. #include "a.h"
  715. #ifndef geteuid
  716.     uid_t geteuid();
  717. #endif
  718. int main() {
  719. /* Guess, don't test.  Ugh.  Testing would require running conf.sh setuid.  */
  720. /* seteuid() isn't standardized yet, so the guess below may well be wrong.  */
  721. #if !_POSIX_VERSION || _POSIX_VERSION<=199009L&&!defined(sgi)&&!defined(__sgi__)&&!defined(sun)&&!defined(__sun__)
  722.     exitmain(1);
  723. #else
  724.     exitmain(seteuid(geteuid()) != 0);
  725. #endif
  726. }
  727. EOF
  728.     $RM || exit
  729.     if ($CL a.c $L && ./a.out) >&2
  730.     then has_seteuid=1
  731.     else has_seteuid=0
  732.     fi
  733. esac
  734. echo "$a#define has_seteuid $has_seteuid $z/* Does seteuid() work?  See README.  */"
  735.  
  736. : has_setuid
  737. h=$has_seteuid
  738. case $h in
  739. 0)
  740.     cat >a.c <<'EOF'
  741. #include "a.h"
  742. #ifndef getuid
  743.     uid_t getuid();
  744. #endif
  745. int main() { exitmain(setuid(getuid()) != 0); }
  746. EOF
  747.     $RM || exit
  748.     ($CL a.c $L && ./a.out) >&2 && h=1
  749. esac
  750. echo "$a#define has_setuid $h $z/* Does setuid() exist?  */"
  751.  
  752. : has_signal, signal_args, signal_type, sig_zaps_handler
  753. cat >a.c <<'EOF'
  754. #include "a.h"
  755. #ifndef getpid
  756.     pid_t getpid();
  757. #endif
  758. #if !defined(signal) && declare_signal
  759.     signal_type (*signal P((int,signal_type(*)signal_args)))signal_args;
  760. #endif
  761. signal_type nothing(i) int i; {}
  762. int main(argc, argv) int argc; char **argv;
  763. {
  764.     signal(SIGINT, nothing);
  765.     while (--argc)
  766.         kill(getpid(), SIGINT);
  767.     exitmain(0);
  768. }
  769. EOF
  770. for declare_signal in 1 0
  771. do
  772.     for signal_type in void int
  773.     do
  774.         for signal_args in 'P((int))' '()'
  775.         do
  776.             $RM || exit
  777.             ($CL \
  778.                 -Ddeclare_signal=$declare_signal \
  779.                 -Dsignal_args="$signal_args" \
  780.                 -Dsignal_type=$signal_type \
  781.                     a.c $L && ./a.out 1) >&2 && break
  782.         done && break
  783.     done && break
  784. done || {
  785.     echo >&2 "cannot deduce signal_args, signal_type"
  786.     exit 1
  787. }
  788. if ./a.out 1 2 >&2
  789. then z=0
  790. else z=1
  791. fi
  792. cat <<EOF
  793. #define has_signal $has_signal /* Does signal() work?  */
  794. #define signal_args $signal_args /* arguments of signal handlers */
  795. #define signal_type $signal_type /* type returned by signal handlers */
  796. #define sig_zaps_handler $z /* Must a signal handler reinvoke signal()?  */
  797. EOF
  798.  
  799. : has_sigaction
  800. cat >a.c <<'EOF'
  801. #include "a.h"
  802. #ifndef getpid
  803.     pid_t getpid();
  804. #endif
  805. static sig_atomic_t volatile gotsig;
  806. static void getsig(i) int i; { gotsig = 1; }
  807. int main(argc, argv) int argc; char **argv;
  808. {
  809.     struct sigaction s;
  810.     sigset_t t;
  811.     if (sigemptyset(&t) != 0  ||  sigaddset(&t, SIGINT) != 0)
  812.         exitmain(1);
  813.     if (sigaction(SIGINT, (struct sigaction const*)0, &s) != 0)
  814.         exitmain(1);
  815.     s.sa_handler = getsig;
  816.     s.sa_mask = t;
  817.     if (sigaction(SIGINT, &s, (struct sigaction*)0) != 0)
  818.         exitmain(1);
  819.     kill(getpid(), SIGINT);
  820.     exitmain(gotsig != 1);
  821. }
  822. EOF
  823. $RM || exit
  824. if ($CL a.c $L && ./a.out) >&2
  825. then has_sigaction=1
  826. else has_sigaction=0
  827. fi
  828. echo "#define has_sigaction $has_sigaction /* Does struct sigaction work?  */"
  829.  
  830. : has_sigblock, sigmask
  831. a='/* ' z='*/ '
  832. b='/* ' y='*/ '
  833. case $has_sigaction in
  834. 1)
  835.     h=? n=?;;
  836. *)
  837.     a= z=
  838.     cat >a.c <<'EOF'
  839. #include "a.h"
  840. #include <signal.h>
  841. #if define_sigmask
  842. #    define sigmask(s) (1 << ((s)-1))
  843. #endif
  844. int main()
  845. {
  846.     sigblock(sigmask(SIGHUP));
  847.     exitmain(kill(getpid(), SIGHUP) != 0);
  848. }
  849. EOF
  850.     if $RM || exit; ($CL a.c $L && ./a.out) >&2
  851.     then h=1
  852.     elif $RM || exit; ($CL -Ddefine_sigmask=1 a.c $L && ./a.out) >&2
  853.     then h=1 b= y=
  854.     else h=0
  855.     fi
  856. esac
  857. echo "$a#define has_sigblock $h $z/* Does sigblock() work?  */"
  858. echo "$b#define sigmask(s) (1 << ((s)-1)) $y/* Yield mask for signal number.  */"
  859.  
  860. : has_sys_siglist
  861. cat >a.c <<'EOF'
  862. #include "a.h"
  863. #ifndef sys_siglist
  864.     extern char const *sys_siglist[];
  865. #endif
  866. int main() { exitmain(!sys_siglist[1][0]); }
  867. EOF
  868. $RM || exit
  869. if ($CL a.c $L && ./a.out) >&2
  870. then h=1
  871. else h=0
  872. fi
  873. echo "#define has_sys_siglist $h /* Does sys_siglist[] work?  */"
  874.  
  875. : fread_type, Fread, Fwrite
  876. cat >a.c <<'EOF'
  877. #define CHAR1 '#' /* the first character in this file */
  878. #include "a.h"
  879. #if !defined(fread) && declare_fread
  880.     fread_type fread P((void*,freadarg_type,freadarg_type,FILE*));
  881. #endif
  882. int main()
  883. {
  884.     char b;
  885.     exitmain(!(
  886.         fread(&b, (freadarg_type)1, (freadarg_type)1, stdin) == 1  &&
  887.         b==CHAR1
  888.     ));
  889. }
  890. EOF
  891. for declare_fread in 1 0
  892. do
  893.     for fread_type in ssize_t size_t int unsigned
  894.     do
  895.         for freadarg_type in size_t ssize_t unsigned int
  896.         do
  897.             $RM || exit
  898.             (
  899.                 $CL \
  900.                     -Ddeclare_fread=$declare_fread \
  901.                     -Dfreadarg_type=$freadarg_type \
  902.                     -Dfread_type=$fread_type \
  903.                     a.c $L &&
  904.                 ./a.out <a.c
  905.             ) >&2 && break
  906.         done && break
  907.     done && break
  908. done || {
  909.     echo >&2 "cannot deduce fread types"
  910.     exit 1
  911. }
  912. cat <<EOF
  913. typedef $fread_type fread_type; /* type returned by fread() and fwrite() */
  914. typedef $freadarg_type freadarg_type; /* type of their size arguments */
  915. EOF
  916.  
  917. : malloc_type
  918. cat >a.c <<'EOF'
  919. #include "a.h"
  920. typedef void *malloc_type;
  921. #ifndef malloc
  922.     malloc_type malloc();
  923. #endif
  924. int main() { exitmain(!malloc(1)); }
  925. EOF
  926. if $CS a.c $LS >&2
  927. then t=void
  928. else t=char
  929. fi
  930. echo "typedef $t *malloc_type; /* type returned by malloc() */"
  931.  
  932. : has_getcwd
  933. cat >a.c <<'EOF'
  934. #include "a.h"
  935. #ifndef getcwd
  936.     char *getcwd();
  937. #endif
  938. char buf[10000];
  939. int main() { exitmain(!getcwd(buf,10000)); }
  940. EOF
  941. $RM || exit
  942. if ($CL a.c $L && ./a.out) >&2
  943. then has_getcwd=1
  944. else has_getcwd=0
  945. fi
  946. echo "#define has_getcwd $has_getcwd /* Does getcwd() work?  */"
  947.  
  948. : has_getwd
  949. case $has_getcwd in
  950. 1)
  951.     a='/* ' z='*/ ' h=?;;
  952. *)
  953.     a= z=
  954.     cat >a.c <<'EOF'
  955. #include "a.h"
  956. #include <sys/param.h>
  957. #ifndef getwd
  958.     char *getwd();
  959. #endif
  960. char buf[MAXPATHLEN];
  961. int main() { exitmain(!getwd(buf)); }
  962. EOF
  963.     $RM || exit
  964.     if ($CL a.c $L && ./a.out) >&2
  965.     then h=1
  966.     else h=0
  967.     fi
  968. esac
  969. echo "$a#define has_getwd $h $z/* Does getwd() work?  */"
  970.  
  971. : has_mktemp
  972. cat >a.c <<'EOF'
  973. #include "a.h"
  974. #ifndef mktemp
  975.     char *mktemp();
  976. #endif
  977. int main()
  978. {
  979.     char b[9];
  980.     strcpy(b, "a.XXXXXX");
  981.     exitmain(!mktemp(b));
  982. }
  983. EOF
  984. $RM || exit
  985. if ($CL a.c $L && ./a.out) >&2
  986. then h=1
  987. else h=0
  988. fi
  989. echo "#define has_mktemp $h /* Does mktemp() work?  */"
  990.  
  991. : has_NFS
  992. echo "#define has_NFS 1 /* Might NFS be used?  */"
  993.  
  994. : strchr
  995. cat >a.c <<'EOF'
  996. #include "a.h"
  997. #ifndef strchr
  998.     char *strchr();
  999. #endif
  1000. int main() {exitmain(!strchr("abc", 'c'));}
  1001. EOF
  1002. $RM || exit
  1003. if ($CL a.c $L && ./a.out) >&2
  1004. then a='/* ' z='*/ '
  1005. else a= z=
  1006. fi
  1007. echo "$a#define strchr index $z/* Use old-fashioned name for strchr()?  */"
  1008.  
  1009. : strrchr
  1010. cat >a.c <<'EOF'
  1011. #include "a.h"
  1012. #ifndef strrchr
  1013.     char *strrchr();
  1014. #endif
  1015. int main() {exitmain(!strrchr("abc", 'c'));}
  1016. EOF
  1017. $RM || exit
  1018. if ($CL a.c $L && ./a.out) >&2
  1019. then a='/* ' z='*/ '
  1020. else a= z=
  1021. fi
  1022. echo "$a#define strrchr rindex $z/* Use old-fashioned name for strrchr()?  */"
  1023.  
  1024. : bad_unlink
  1025. cat >a.c <<'EOF'
  1026. #include "a.h"
  1027. int main() { exitmain(unlink("a.c") != 0); }
  1028. EOF
  1029. $RM && chmod -w a.c || exit
  1030. if $CL a.c $L >&2 && ./a.out >/dev/null && test ! -f a.c
  1031. then b=0
  1032. else b=1
  1033. fi
  1034. rm -f a.c || exit
  1035. echo "#define bad_unlink $b /* Does unlink() fail on unwritable files?  */"
  1036.  
  1037. : has_vfork, has_fork, has_spawn, has_wait, has_waitpid, RCS_SHELL
  1038. cat >a.c <<'EOF'
  1039. #include "a.h"
  1040. #ifndef getpid
  1041.     pid_t getpid();
  1042. #endif
  1043. #if TRY_VFORK
  1044. #    ifndef vfork
  1045.         pid_t vfork();
  1046. #    endif
  1047. #else
  1048. #    ifndef fork
  1049.         pid_t fork();
  1050. #    endif
  1051. #    undef vfork
  1052. #    define vfork fork
  1053. #endif
  1054. #if TRY_WAITPID
  1055. #    ifndef waitpid
  1056.         pid_t waitpid();
  1057. #    endif
  1058. #else
  1059. #    ifndef wait
  1060.         pid_t wait();
  1061. #    endif
  1062. #endif
  1063. pid_t child;
  1064. int status;
  1065. struct stat st;
  1066. int main()
  1067. {
  1068.     pid_t parent = getpid();
  1069.     if (!(child = vfork())) {
  1070.         /* Tickle vfork/compiler bug (e.g. sparc gcc -O (1.37.1).  */
  1071.         pid_t i = getpid(), j = getpid();
  1072.         if (i!=getpid() || j!=getpid())
  1073.             _exit(!i);
  1074.         /* Tickle file descriptor bug (e.g. IRIX 3.3).  */
  1075.         _exit(close(1) != 0);
  1076.     } else {
  1077. #        if TRY_WAITPID
  1078.             if (waitpid(child, &status, 0) != child)
  1079.                 exitmain(1);
  1080. #        else
  1081.             while (wait(&status) != child)
  1082.                 ;
  1083. #        endif
  1084.         /* Test for presence of bugs.  */
  1085.         exitmain(status  ||  parent != getpid()  ||  fstat(1,&st) != 0);
  1086.     }
  1087. }
  1088. EOF
  1089. $RM || exit
  1090. if ($CL -DTRY_VFORK=1 a.c $L && ./a.out) >&2
  1091. then has_vfork=1
  1092. else has_vfork=0
  1093. fi
  1094. echo "#define has_vfork $has_vfork /* Does vfork() work?  */"
  1095. h=$has_vfork
  1096. case $h in
  1097. 0)
  1098.     $RM || exit
  1099.     ($CL a.c $L && ./a.out) >&2 && h=1
  1100. esac
  1101. echo "#define has_fork $h /* Does fork() work?  */"
  1102. $RM || exit
  1103. if ($CL -DTRY_VFORK=$has_vfork -DTRY_WAITPID=1 a.c $L && ./a.out) >&2
  1104. then h=1
  1105. else h=0
  1106. fi
  1107. echo "#define has_spawn 0 /* Does spawn*() work?  */"
  1108. echo "#define has_wait 1 /* Does wait() work?  */"
  1109. echo "#define has_waitpid $h /* Does waitpid() work?  */"
  1110. echo '#define RCS_SHELL "/bin/sh" /* shell to run RCS subprograms */'
  1111.  
  1112. : has_vfprintf
  1113. cat >a.c <<'EOF'
  1114. #include "a.h"
  1115. #if has_prototypes
  1116. int p(char const*format,...)
  1117. #else
  1118. /*VARARGS1*/ int p(format, va_alist) char *format; va_dcl
  1119. #endif
  1120. {
  1121.     int r;
  1122.     va_list args;
  1123.     vararg_start(args, format);
  1124.     r = vfprintf(stderr, format, args);
  1125.     va_end(args);
  1126.     return r;
  1127. }
  1128. int main() { exitmain(p("") != 0); }
  1129. EOF
  1130. $RM || exit
  1131. if ($CL a.c $L && ./a.out) >&2
  1132. then h=1
  1133. else h=0
  1134. fi
  1135. echo "#define has_vfprintf $h /* Does vfprintf() work?  */"
  1136.  
  1137. : has__doprintf, has__doprnt
  1138. case $h in
  1139. 1)
  1140.     h=? a='/* ' z='*/ ';;
  1141. *)
  1142.     a= z=
  1143.     cat >a.c <<'EOF'
  1144. #include "a.h"
  1145. #if has_prototypes
  1146. int p(char const*format,...)
  1147. #else
  1148. /*VARARGS1*/ int p(format, va_alist) char *format; va_dcl
  1149. #endif
  1150. {
  1151.     va_list args;
  1152.     vararg_start(args, format);
  1153. #    if TRY__DOPRINTF
  1154.         _doprintf(stderr, format, args);
  1155. #    else
  1156.         _doprnt(format, args, stderr);
  1157. #    endif
  1158.     va_end(args);
  1159. }
  1160. int main() { p(""); exitmain(ferror(stderr) != 0); }
  1161. EOF
  1162.     $RM || exit
  1163.     if ($CL -DTRY__DOPRINTF=1 a.c $L && ./a.out) >&2
  1164.     then h=1
  1165.     else h=0
  1166.     fi
  1167. esac
  1168. echo "$a#define has__doprintf $h $z/* Does _doprintf() work?  */"
  1169. case $h in
  1170. 0)
  1171.     $RM || exit
  1172.     if ($CL a.c $L && ./a.out) >&2
  1173.     then h=1
  1174.     else h=0
  1175.     fi
  1176.     a= z=;;
  1177. *)
  1178.     h=? a='/* ' z='*/ '
  1179. esac
  1180. echo "$a#define has__doprnt $h $z/* Does _doprnt() work?  */"
  1181.  
  1182. : EXIT_FAILURE
  1183. cat >a.c <<'EOF'
  1184. #include "a.h"
  1185. int main() { exitmain(EXIT_FAILURE); }
  1186. EOF
  1187. $RM || exit
  1188. if $CL a.c $L >&2 && ./a.out
  1189. then a= z=
  1190. else a='/* ' z='*/ '
  1191. fi
  1192. echo "$a#undef EXIT_FAILURE $z/* Uncomment this if EXIT_FAILURE is broken.  */"
  1193.  
  1194. : large_memory
  1195. echo "#define large_memory $has_mmap /* Can main memory hold entire RCS files?  */"
  1196.  
  1197. : ULONG_MAX
  1198. cat >a.c <<'EOF'
  1199. #include "a.h"
  1200. #ifdef ULONG_MAX
  1201.     /*
  1202.      * "#if ULONG_MAX/10 <= 0" does not always work,
  1203.      * because some buggy implementations put casts in ULONG_MAX.
  1204.      */
  1205.     int main() { exitmain(ULONG_MAX/10 <= 0); }
  1206. #else
  1207.     int main() { exitmain(1); }
  1208. #endif
  1209. EOF
  1210. $RM || exit
  1211. if $CL a.c $L >&2 && ./a.out
  1212. then a='/* ' z='*/ '
  1213. else a= z=
  1214. fi
  1215. echo "$a#undef ULONG_MAX $z/* Uncomment this if ULONG_MAX is broken (e.g. < 0).  */"
  1216.  
  1217. : struct utimbuf
  1218. cat >a.c <<'EOF'
  1219. #include "a.h"
  1220. struct utimbuf s;
  1221. int main() { s.actime = s.modtime = 1; exitmain(utime("a.c", &s) != 0); }
  1222. EOF
  1223. $RM || exit
  1224. if ($CL a.c $L && ./a.out) >&2
  1225. then a='/* ' z=' */'
  1226. else a= z=
  1227. fi
  1228. echo "${a}struct utimbuf { time_t actime, modtime; };$z /* Uncomment this if needed.  */"
  1229.  
  1230. : CO
  1231. echo "#define CO \"${RCSPREFIX}co\" /* name of 'co' program */"
  1232.  
  1233. : COMPAT2
  1234. echo "#define COMPAT2 $COMPAT2 /* Are version 2 files supported?  */"
  1235.  
  1236. : DATEFORM
  1237. cat >a.c <<'EOF'
  1238. #include "a.h"
  1239. int main() { printf("%.2d", 1); exitmain(0); }
  1240. EOF
  1241. $RM && $CL a.c $L >&2 && r=`./a.out` || exit
  1242. case $r in
  1243. 01)    f=%.2d;;
  1244. *)    f=%02d
  1245. esac
  1246. echo "#define DATEFORM \"$f.$f.$f.$f.$f.${f}\" /* e.g. 01.01.01.01.01.01 */"
  1247.  
  1248. : DIFF
  1249. echo "#define DIFF \"${DIFF}\" /* name of 'diff' program */"
  1250.  
  1251. : DIFF3
  1252. echo "#define DIFF3 \"${DIFF3}\" /* name of 'diff3' program */"
  1253.  
  1254. echo "#define DIFF3_BIN $DIFF3_BIN /* Is diff3 user-visible (not the /usr/lib auxiliary)?  */"
  1255.  
  1256. : DIFF_FLAGS
  1257. dfs=
  1258. for df in $DIFF_FLAGS
  1259. do dfs="$dfs, \"${df}\""
  1260. done
  1261. echo "#define DIFF_FLAGS $dfs /* Make diff output suitable for RCS.  */"
  1262.  
  1263. : DIFF_L
  1264. echo "#define DIFF_L $DIFF_L /* Does diff -L work? */"
  1265.  
  1266. : DIFF_SUCCESS, DIFF_FAILURE, DIFF_TROUBLE
  1267. cat <<EOF
  1268. #define DIFF_SUCCESS $DIFF_SUCCESS /* DIFF status if no differences are found */
  1269. #define DIFF_FAILURE $DIFF_FAILURE /* DIFF status if differences are found */
  1270. #define DIFF_TROUBLE $DIFF_TROUBLE /* DIFF status if trouble */
  1271. EOF
  1272.  
  1273. : ED
  1274. echo "#define ED \"${ED}\" /* name of 'ed' program (used only if !DIFF3_BIN) */"
  1275.  
  1276. : MERGE
  1277. echo "#define MERGE \"${RCSPREFIX}merge\" /* name of 'merge' program */"
  1278.  
  1279. : '*SLASH*', ROOTPATH, TMPDIR, X_DEFAULT
  1280. case ${PWD-`pwd`} in
  1281. /*) # Posix
  1282.     SLASH=/
  1283.     qSLASH="'/'"
  1284.     SLASHes=$qSLASH
  1285.     isSLASH='#define isSLASH(c) ((c) == SLASH)'
  1286.     ROOTPATH='isSLASH((p)[0])'
  1287.     X_DEFAULT=",v$SLASH";;
  1288. ?:[/\\]*) # MS-DOS
  1289.     SLASH='\'
  1290.     qSLASH="'\\\\'"
  1291.     SLASHes="$qSLASH: case '/': case ':'"
  1292.     isSLASH='int isSLASH P((int));'
  1293.     ROOTPATH='((p)[0] && (p)[1]==':' && isSLASH((p)[2]))'
  1294.     X_DEFAULT="$SLASH,v";;
  1295. *)
  1296.     echo >&2 "cannot deduce SLASH"; exit 1
  1297. esac
  1298. cat <<EOF
  1299. #define TMPDIR "${SLASH}tmp" /* default directory for temporary files */
  1300. #define SLASH $qSLASH /* principal pathname separator */
  1301. #define SLASHes $SLASHes /* \`case SLASHes:' labels all pathname separators */
  1302. $isSLASH /* Is arg a pathname separator?  */
  1303. #define ROOTPATH(p) $ROOTPATH /* Is p an absolute pathname?  */
  1304. #define X_DEFAULT "$X_DEFAULT" /* default value for -x option */
  1305. EOF
  1306.  
  1307. : DIFF_ABSOLUTE
  1308. case $DIFF in
  1309. "$SLASH"*) a=1;;
  1310. *) a=0
  1311. esac
  1312. echo "#define DIFF_ABSOLUTE $a /* Is ROOTPATH(DIFF) true?  */"
  1313.  
  1314. : ALL_ABSOLUTE
  1315. a=1
  1316. for i in "$DIFF" "$DIFF3" "$ED" "$RCSPREFIX" "$SENDMAIL"/
  1317. do
  1318.     case $i in
  1319.     "$SLASH"* | "\"$SLASH"*) ;;
  1320.     *) a=0 break
  1321.     esac
  1322. done
  1323. echo "#define ALL_ABSOLUTE $a /* Are all subprograms absolute pathnames?  */"
  1324.  
  1325. : SENDMAIL
  1326. case $SENDMAIL in
  1327. '') a='/* ' z='*/ ';;
  1328. *) a= z=
  1329. esac
  1330. echo "$a#define SENDMAIL $SENDMAIL $z/* how to send mail */"
  1331.  
  1332. : TZ_must_be_set
  1333. echo "#define TZ_must_be_set 0 /* Must TZ be set for gmtime() to work?  */"
  1334.  
  1335.  
  1336. : standard function declarations
  1337.  
  1338. cat <<'EOF'
  1339.  
  1340.  
  1341.  
  1342. /* Adjust the following declarations as needed.  */
  1343.  
  1344.  
  1345. #if __GNUC__ && !__STRICT_ANSI__
  1346. #    define exiting volatile /* GCC extension: function cannot return */
  1347. #else
  1348. #    define exiting
  1349. #endif
  1350. EOF
  1351.  
  1352. cat >a.ha <<EOF
  1353.  
  1354. #if has_ftruncate
  1355.     int ftruncate P((int,off_t));
  1356. #endif
  1357.  
  1358. /* <sys/mman.h> */
  1359. #if has_madvise
  1360.     int madvise P((caddr_t,size_t,int));
  1361. #endif
  1362. #if has_mmap
  1363.     caddr_t mmap P((caddr_t,size_t,int,int,int,off_t));
  1364.     int munmap P((caddr_t,size_t));
  1365. #endif
  1366.  
  1367.  
  1368. /* Posix (ISO/IEC 9945-1: 1990 / IEEE Std 1003.1-1990) */
  1369. /* These definitions are for the benefit of non-Posix hosts, and */
  1370. /* Posix hosts that have Standard C compilers but traditional include files.  */
  1371. /* Unfortunately, mixed-up hosts are all too common.  */
  1372.  
  1373. /* <fcntl.h> */
  1374. #ifdef F_DUPFD
  1375.     int fcntl P((int,int,...));
  1376. #else
  1377.     int dup2 P((int,int));
  1378. #endif
  1379. #ifndef O_BINARY /* some non-Posix hosts need O_BINARY */
  1380. #    define O_BINARY 0 /* no effect on Posix */
  1381. #endif
  1382. #ifdef O_CREAT
  1383. #    define open_can_creat 1
  1384. #else
  1385. #    define open_can_creat 0
  1386. #    define O_RDONLY 0
  1387. #    define O_WRONLY 1
  1388. #    define O_RDWR 2
  1389. #    define O_CREAT 01000
  1390. #    define O_TRUNC 02000
  1391.     int creat P((char const*,mode_t));
  1392. #endif
  1393. #ifndef O_EXCL
  1394. #    define O_EXCL 0
  1395. #endif
  1396.  
  1397. /* <pwd.h> */
  1398. #if has_getpwuid
  1399.     struct passwd *getpwuid P((uid_t));
  1400. #endif
  1401.  
  1402. /* <signal.h> */
  1403. #if has_sigaction
  1404.     int sigaction P((int,struct sigaction const*,struct sigaction*));
  1405.     int sigaddset P((sigset_t*,int));
  1406.     int sigemptyset P((sigset_t*));
  1407. #else
  1408. #if has_sigblock
  1409.     /* BSD */
  1410.     int sigblock P((int));
  1411.     int sigmask P((int));
  1412.     int sigsetmask P((int));
  1413. #endif
  1414. #endif
  1415.  
  1416. /* <stdio.h> */
  1417. FILE *fdopen P((int,char const*));
  1418. int fileno P((FILE*));
  1419.  
  1420. /* <sys/stat.h> */
  1421. int chmod P((char const*,mode_t));
  1422. int fstat P((int,struct stat*));
  1423. int stat P((char const*,struct stat*));
  1424. mode_t umask P((mode_t));
  1425. #if has_fchmod
  1426.     int fchmod P((int,mode_t));
  1427. #endif
  1428. #ifndef S_IRUSR
  1429. #    ifdef S_IREAD
  1430. #        define S_IRUSR S_IREAD
  1431. #    else
  1432. #        define S_IRUSR 0400
  1433. #    endif
  1434. #    ifdef S_IWRITE
  1435. #        define S_IWUSR S_IWRITE
  1436. #    else
  1437. #        define S_IWUSR (S_IRUSR/2)
  1438. #    endif
  1439. #endif
  1440. #ifndef S_IRGRP
  1441. #    if has_getuid
  1442. #        define S_IRGRP (S_IRUSR / 0010)
  1443. #        define S_IWGRP (S_IWUSR / 0010)
  1444. #        define S_IROTH (S_IRUSR / 0100)
  1445. #        define S_IWOTH (S_IWUSR / 0100)
  1446. #    else
  1447.         /* single user OS -- not Posix or Unix */
  1448. #        define S_IRGRP 0
  1449. #        define S_IWGRP 0
  1450. #        define S_IROTH 0
  1451. #        define S_IWOTH 0
  1452. #    endif
  1453. #endif
  1454. #ifndef S_ISREG
  1455. #    define S_ISREG(n) (((n) & S_IFMT) == S_IFREG)
  1456. #endif
  1457.  
  1458. /* <sys/wait.h> */
  1459. #if has_wait
  1460.     pid_t wait P((int*));
  1461. #endif
  1462. #ifndef WEXITSTATUS
  1463. #    define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
  1464. #    undef WIFEXITED /* Avoid 4.3BSD incompatibility with Posix.  */
  1465. #endif
  1466. #ifndef WIFEXITED
  1467. #    define WIFEXITED(stat_val) (!((stat_val) & 255))
  1468. #endif
  1469.  
  1470. /* <unistd.h> */
  1471. char *getlogin P((void));
  1472. int close P((int));
  1473. int isatty P((int));
  1474. int link P((char const*,char const*));
  1475. int open P((char const*,int,...));
  1476. int unlink P((char const*));
  1477. int _filbuf P((FILE*)); /* keeps lint quiet in traditional C */
  1478. int _flsbuf P((int,FILE*)); /* keeps lint quiet in traditional C */
  1479. long pathconf P((char const*,int));
  1480. ssize_t write P((int,void const*,size_t));
  1481. #ifndef STDIN_FILENO
  1482. #    define STDIN_FILENO 0
  1483. #    define STDOUT_FILENO 1
  1484. #    define STDERR_FILENO 2
  1485. #endif
  1486. #if has_fork
  1487. #    if !has_vfork
  1488. #        undef vfork
  1489. #        define vfork fork
  1490. #    endif
  1491.     pid_t vfork P((void)); /* vfork is nonstandard but faster */
  1492. #endif
  1493. #if has_getcwd || !has_getwd
  1494.     char *getcwd P((char*,size_t));
  1495. #else
  1496.     char *getwd P((char*));
  1497. #endif
  1498. #if has_getuid
  1499.     uid_t getuid P((void));
  1500. #endif
  1501. #if has_readlink
  1502.     ssize_t readlink P((char const*,char*,size_t)); /* BSD; not standard yet */
  1503. #endif
  1504. #if has_setuid
  1505. #    if !has_seteuid
  1506. #        undef seteuid
  1507. #        define seteuid setuid
  1508. #    endif
  1509.     int seteuid P((uid_t));
  1510.     uid_t geteuid P((void));
  1511. #endif
  1512. #if has_spawn
  1513.     int spawnv P((int,char const*,char*const*));
  1514. #    if ALL_ABSOLUTE
  1515. #        define spawn_RCS spawnv
  1516. #    else
  1517. #        define spawn_RCS spawnvp
  1518.         int spawnvp P((int,char const*,char*const*));
  1519. #    endif
  1520. #else
  1521.     int execv P((char const*,char*const*));
  1522. #    if ALL_ABSOLUTE
  1523. #        define exec_RCS execv
  1524. #    else
  1525. #        define exec_RCS execvp
  1526.         int execvp P((char const*,char*const*));
  1527. #    endif
  1528. #endif
  1529.  
  1530. /* utime.h */
  1531. int utime P((char const*,struct utimbuf const*));
  1532.  
  1533.  
  1534. /* Standard C library */
  1535. /* These definitions are for the benefit of hosts that have */
  1536. /* traditional C include files, possibly with Standard C compilers.  */
  1537. /* Unfortunately, mixed-up hosts are all too common.  */
  1538.  
  1539. /* <errno.h> */
  1540. extern int errno;
  1541.  
  1542. /* <limits.h> */
  1543. #ifndef ULONG_MAX
  1544.     /* This does not work in #ifs, but it's good enough for us.  */
  1545. #    define ULONG_MAX ((unsigned long)-1)
  1546. #endif
  1547.  
  1548. /* <signal.h> */
  1549. #if has_signal
  1550.     signal_type (*signal P((int,signal_type(*)signal_args)))signal_args;
  1551. #endif
  1552.  
  1553. /* <stdio.h> */
  1554. FILE *fopen P((char const*,char const*));
  1555. fread_type fread P((void*,freadarg_type,freadarg_type,FILE*));
  1556. fread_type fwrite P((void const*,freadarg_type,freadarg_type,FILE*));
  1557. int fclose P((FILE*));
  1558. int feof P((FILE*));
  1559. int ferror P((FILE*));
  1560. int fflush P((FILE*));
  1561. int fprintf P((FILE*,char const*,...));
  1562. int fputs P((char const*,FILE*));
  1563. int fseek P((FILE*,long,int));
  1564. int printf P((char const*,...));
  1565. int rename P((char const*,char const*));
  1566. int sprintf P((char*,char const*,...));
  1567. long ftell P((FILE*));
  1568. void clearerr P((FILE*));
  1569. void perror P((char const*));
  1570. #ifndef L_tmpnam
  1571. #    define L_tmpnam 32 /* power of 2 > sizeof("/usr/tmp/xxxxxxxxxxxxxxx") */
  1572. #endif
  1573. #ifndef SEEK_SET
  1574. #    define SEEK_SET 0
  1575. #endif
  1576. #if has_mktemp
  1577.     char *mktemp P((char*)); /* traditional */
  1578. #else
  1579.     char *tmpnam P((char*));
  1580. #endif
  1581. #if has_vfprintf
  1582.     int vfprintf P((FILE*,char const*,va_list));
  1583. #else
  1584. #if has__doprintf
  1585.     void _doprintf P((FILE*,char const*,va_list)); /* Minix */
  1586. #else
  1587.     void _doprnt P((char const*,va_list,FILE*)); /* BSD */
  1588. #endif
  1589. #endif
  1590.  
  1591. /* <stdlib.h> */
  1592. char *getenv P((char const*));
  1593. exiting void _exit P((int));
  1594. exiting void exit P((int));
  1595. malloc_type malloc P((size_t));
  1596. malloc_type realloc P((malloc_type,size_t));
  1597. void free P((malloc_type));
  1598. #ifndef EXIT_FAILURE
  1599. #    define EXIT_FAILURE 1
  1600. #endif
  1601. #ifndef EXIT_SUCCESS
  1602. #    define EXIT_SUCCESS 0
  1603. #endif
  1604. #if !has_fork && !has_spawn
  1605.     int system P((char const*));
  1606. #endif
  1607.  
  1608. /* <string.h> */
  1609. char *strcpy P((char*,char const*));
  1610. char *strchr P((char const*,int));
  1611. char *strrchr P((char const*,int));
  1612. int memcmp P((void const*,void const*,size_t));
  1613. int strcmp P((char const*,char const*));
  1614. size_t strlen P((char const*));
  1615. void *memcpy P((void*,void const*,size_t));
  1616. #if has_memmove
  1617.     void *memmove P((void*,void const*,size_t));
  1618. #endif
  1619.  
  1620. /* <time.h> */
  1621. time_t time P((time_t*));
  1622. EOF
  1623.  
  1624. cat >a.c <<'EOF'
  1625. #include "a.h"
  1626. #define a 0
  1627. #define b 1
  1628. #if h==a
  1629. #    include "a.ha"
  1630. #else
  1631. #    include "a.hb"
  1632. #endif
  1633. int main() { exitmain(0); }
  1634. EOF
  1635.  
  1636. # Comment out lines in a.ha that the compiler rejects.
  1637. # a.ha may not contain comments that cross line boundaries.
  1638. # Leave the result in a.h$h.
  1639. h=a l=1
  1640. U=`wc -l <a.ha | sed 's| ||g'`
  1641. commentOut='s|^[^#/][^/]*|/* & */|'
  1642.  
  1643. until  test $U -lt $l  ||  $CS -Dh=$h a.c $LS >&2
  1644. do
  1645.     case $h in
  1646.     a) i=b;;
  1647.     *) i=a
  1648.     esac
  1649.  
  1650.     # The compiler rejects some line in l..U.
  1651.     # Use binary search to set l to be the index of the first bad line in l..U.
  1652.     u=$U
  1653.     while test $l -lt $u
  1654.     do
  1655.         M=`expr '(' $l + $u ')' / 2`
  1656.         M1=`expr $M + 1`
  1657.         sed "$M1,\$$commentOut" a.h$h >a.h$i || exit
  1658.         if $CS -Dh=$i a.c $LS >&2
  1659.         then l=$M1
  1660.         else u=$M
  1661.         fi
  1662.     done
  1663.  
  1664.     # Comment out the bad line.
  1665.     sed "$l$commentOut" a.h$h >a.h$i || exit
  1666.  
  1667.     h=$i
  1668.     l=`expr $l + 1`
  1669. done
  1670.  
  1671. cat a.h$h
  1672.